import { Component, OnInit, Input } from "@angular/core";
import { AppGlobalService } from "src/app/shared/service/app-global.service";
import { ModalController } from "@ionic/angular";
import { ImgSlidePage } from "../slides-imgage/img-slide.page";

@Component({
  selector: "app-case-remark",
  templateUrl: "./case-remark.component.html",
  styleUrls: ["./case-remark.component.scss"]
})
export class CaseRemarkComponent implements OnInit {
  @Input() tagData: any;

  constructor(
    private appGlobalService: AppGlobalService,
    private modalCtrl: ModalController
  ) { }

  imgList;


  ngOnInit() {
    // tslint:disable-next-line:no-string-literal
    if (this.tagData.data.imageList && this.tagData.data.imageList.length > 4) {
      this.imgList = this.tagData.data.imageList.slice(0, 4);
    } else if (this.tagData.data.imageList && this.tagData.data.imageList.length > 0 && this.tagData.data.imageList.length < 4) {
      this.imgList = this.tagData.data.imageList.slice(0, this.tagData.data.imageList.length - 1);
    } else {
      this.imgList = [];
    }

  }

  handleClick(item) {
    const sessionId = localStorage.getItem("sessionId");
    const pageParams = {
      pageId: item.target,
      params: item.params,
      sessionId
    };
    this.appGlobalService.goToForward(pageParams);
  }

  async openImage(index, images) {
    const value = { img: images, index };
    const modal = await this.modalCtrl.create({
      component: ImgSlidePage,
      componentProps: { value: JSON.stringify(value) }
    });
    return await modal.present();
  }
}
